package servlet.admin;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.Admin;
import dao.AdminDAO;
import dao.NewsDAO;

/**
 * Servlet implementation class DeleteNews
 */
@WebServlet("/Delete")
public class Delte extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public Delte() {
        super();
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     *
     *      根据id删除新闻
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        response.setCharacterEncoding("UTF-8");

        AdminDAO adminDAO = new AdminDAO();
        int id = Integer.valueOf(request.getParameter("id"));
        int currentPage = Integer.valueOf(request.getParameter("currentPage"));
        boolean success = adminDAO.deleteAdmin(id);
        request.setAttribute("success", success);
        response.sendRedirect("./jsp/manage/usersList.jsp?currentPage=" + currentPage);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }

}
